package com.heima.controller;

import com.heima.pojo.vo.OrderVo;
import com.heima.service.OrderService;
import com.heima.utils.PageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author 赵超
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/order-service/order")
public class OrderController {
    private final OrderService orderService;

    @GetMapping("/search")
    public PageResult<OrderVo> search(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String orderNo,
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
            @RequestParam(required = false) LocalDate startDate,
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
            @RequestParam(required = false) LocalDate endDate

    ) {
        return orderService.search(pageIndex, pageSize, orderNo, startDate, endDate);
    }
}
